﻿@using KPIS.GERP.Models.ICM
@model BidderQuotation

@{
    ViewBag.Title = "กรอกเหตุผลที่เลือก";
    Layout = "~/Views/Shared/_EmptyLayout.cshtml";
}

@using (Html.BeginForm("Select", "BidderSelect", FormMethod.Post, new { id="form1", @class = "form-horizontal" }))
{
    @Html.AntiForgeryToken()
    @Html.HiddenFor(m=>m.BidderQuoId)
    @Html.HiddenFor(m=>m.Bidder.BidId)
    @Html.HiddenFor(m=>m.PrItemId)

    <div class="block-button-menu-above">
        <a id="cmdClose" href="#" class="btn btn-small button-standard-width btn-danger" data-dismiss="modal" onclick="closeModal()">ปิด</a>
        @Html.ButtonSubmit()
    </div>
    
    <div class="row-fluid" style="padding:10px">
        @Html.ValidationSummary(true, "*กรุณากรอกข้อมูล", new { @class = "alert alert-error" })

        <h4 class="text-info">กรอกเหตุผลที่เลือก</h4>
        ผู้เสนอราคา : <p class="text-error">@Model.Bidder.MasContact.NameTh<br/>
        @(Model.PurchaseRequestItem.ResItemId.HasValue ? Model.PurchaseRequestItem.MasResourceItem.Name : Model.PurchaseRequestItem.Descr)</p>
        ราคา : <p class="text-error">@(Model.NetAmount.HasValue ? Model.NetAmount.Value.ToString("#,##0.00") : "") บาท</p>

        <div class="control-group">
            <div class="control-label">
                เหตุผลที่เลือก
            </div>
            <div class="controls">
                @Html.TextAreaFor(m => m.SelectedReason, new { style="height:100px" })
                @Html.ValidationMessageFor(model => model.SelectedReason)
            </div>
        </div>
    </div>
}

@section scripts
{
    <script>
        $(function () {
            $("#form1").submit(function (e) {
                var currentForm = this;
                bootbox.confirm(function (result) {
                    var _result = result;
                    if (result) {
                        $.ajax({
                            url: currentForm.action,
                            type: currentForm.method,
                            data: $(currentForm).serialize(),
                            success: function (result) {
                                if (result.result) {
                                    bootbox.alert(result.message, "ตกลง", function () {
                                        closeModal();
                                    });
                                }
                                else {
                                    bootbox.alert(result.message, "ตกลง", function () {
                                        bootbox.hideAll();
                                    });
                                }
                            }
                        });

                        return false;
                    }
                });

                return false;
            });
        });

        function closeModal() {
            var $jParent = window.parent.jQuery.noConflict();
            $jParent('#modal').modal('hide');
            //location.reload();
            window.parent.location.href = window.parent.location.href;
        }
    </script>
}